﻿using System;
using System.Collections.Generic;
using NHibernate.Mapping.ByCode;
using Xenta.Enums;

namespace Xenta.Entities
{
    /// <summary>
    /// Represents the item rating entity.
    /// </summary>
    /// <remarks><pre>
    /// The entity regarding the disclosure level.
    /// 
    /// + Entire
    ///  + Extended
    ///   + Base
    ///    | - HolderID
    ///    | - Account(of the Keys level)
    ///    | - Comment(of the same level)
    ///    | - Value
    ///    | - Flags
    ///    | - UpdatedOn
    ///    | - CreatedOn
    ///    + Keys
    ///     + Primary
    ///      | - EntityID
    /// 
    /// Note: upper level includes lower level.
    /// </pre></remarks>
    public class CatalogItemRatingEntity : RatingEntity
    {
        #region Properties

        /// <summary>
        /// Gets or sets the flags.
        /// </summary>
        public virtual CatalogItemRatingFlags Flags
        {
            get
            {
                return (CatalogItemRatingFlags)FlagsValue;
            }
            set
            {
                FlagsValue = (int)value;
            }
        }

        #endregion

        #region Utilities

        protected override void Disclose(IDictionary<String, Object> obj,
            DisclosureLevel level,
            IDictionary<String, String> options)
        {
            base.Disclose(obj, level, options);
            if(level >= DisclosureLevel.Base)
                obj["Flags"] = Flags.ToString();
        }

        #endregion
    }

    /// <summary>
    /// The entity NHibernate mapping.
    /// </summary>
    public class CatalogItemRatingMapping : SubEntityMapping<CatalogItemRatingEntity>
    {
        #region Constants

        /// <summary>
        /// The value to be used as the generic attribute entity discriminator.
        /// </summary>
        public const string DISCRIMINATOR_VALUE = "CATITEM";

        #endregion

        #region Ctors

        /// <summary>
        /// Initializes a new class instance.
        /// </summary>
        public CatalogItemRatingMapping()
        {
            DiscriminatorValue(DISCRIMINATOR_VALUE);
        }

        #endregion
    }
}
